home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
UTILITIE
/
CPU_MEMO
/
0978.ZIP
/
TERM.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-05-31
|
3KB
|
149 lines
name term
page ,132
title Resident Program Termination Routine
comment \
This program gives users a last ditch way to get a program
to peacefully terminate. It ties into the user timer
interrupt, and checks the shift flags to see if it should
activate. If so, it prints a message and issues a DOS
function call 4c, with return code 255.
\
dos_data segment at 40h
org 17h
KB_FLAG label byte ; dangerous hardwired location
dos_data ends
code segment
org 100h ;For COM conversion
assume cs:code, ds:code
DOS_entry label far ;DOS entry point
jmp install
old_timer dd ? ;Old timer interrupt
guard dw 0
debounce db 0
msg1 db 0dh, 0ah, 7, ' Issuing termination request'
db 0dh, 0ah, 0, '$'
RIGHT_SHIFT equ 01h
LEFT_SHIFT equ 02h
CTL_SHIFT equ 04h
ALT_SHIFT equ 08H
TRIGGER equ ALT_SHIFT or LEFT_SHIFT or RIGHT_SHIFT or CTL_SHIFT
timer proc far
sti
push cx
mov cx, cs:guard
jcxz chk_kybd ; ensure guard is clear
pop cx ; otherwise go home
jmp cs: old_timer
chk_kybd: push ds ; check for the trigger
push ax
mov ax, dos_data
mov ds, ax
assume ds:dos_data
mov al, KB_FLAG
and al, TRIGGER
push cs
pop ds
assume ds:code ; al == trigger if set
mov ah, debounce
or ah, ah
jnz do_debounce ; take care of debouncing
cmp al, TRIGGER
jne go_home
do_term: mov guard, -1 ; this is it!
push si
mov si, offset msg1
call write_tty
pop si
mov debounce, -1
; mov guard, 0 ; for debugging: do everything
; jmp go_home ; except the terminate
mov al, 020h
out 020h, al ; make the 8259 happy
mov ah, 4ch
mov al, -1
mov guard, 0
int 21h ; terminate process
do_debounce: cmp al, TRIGGER ; is trigger still on?
je go_home
mov debounce, 0
go_home: pop ax ; no trigger, go home
pop ds
pop cx
jmp cs:old_timer
timer endp
; write a null terminated string indexed by DS:SI
write_tty proc near
lodsb
or al, al
jz wt1
mov ah, 0eh
int 10h
jmp write_tty
wt1: ret
write_tty endp
comment \
Everything past this point will be reclaimed when the install
procedure returns to DOS after the program is first run.
\
greeting db 13,10
db 218,32 dup (196),191,13,10
db 179,' Termination Routine has been ',179,13,10
db 179,' installed in RAM ',179,13,10
db 192,32 dup (196),217,13,10,0,'$'
comment \
The install procedure is invoked through the DOS entry point
when the program is first run. It installs the new interrupt
and prints a message on the console. When done, it returns to
DOS and allows the space it occupies itself to be reclaimed.
\
assume cs:code
install proc near
push cs ;Set DS up for
pop ds ; interrupt replace
mov ax, 351ch ; user timer.
int 21h
mov word ptr old_timer, bx
mov word ptr old_timer+2, es
mov dx, offset timer
mov ax, 251ch
int 21h
mov dx, offset greeting
mov si, dx
call write_tty
int 27h ;Terminate & stay res
install endp
code ends
end DOS_entry ;Must be far label